package org.blogwu.learn.multithread.chapter2.demo7;

public class ThreadGroupName {

    public static void main(String[] args) {
        ThreadGroup threadGroup = new ThreadGroup("myGroup ");
        Thread thread1 = new Thread(threadGroup, new Thread1(), "t1");
        Thread thread2 = new Thread(threadGroup, new Thread1(), "t2");
        thread1.start();
        thread2.start();
        System.out.println(threadGroup.activeCount());
        threadGroup.list();
    }
}

class Thread1 implements Runnable {

    @Override
    public void run() {
        String groupName = Thread.currentThread().getThreadGroup().getName();
//        System.out.println(groupName);
        while (true) {
            System.out.println("I am " + groupName);
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
